package com.me.seckill.service.impl;

import com.me.seckill.mapper.StockOrderMapper;
import com.me.seckill.pojo.Stock;
import com.me.seckill.pojo.StockOrder;
import com.me.seckill.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Function:
 *
 * @author crossoverJie
 *         Date: 01/05/2018 14:10
 * @since JDK 1.8
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class OrderServiceImpl implements OrderService {

    private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Autowired
    private StockOrderMapper orderMapper;

    @Override
    public int createOrder(Stock stock) {
        StockOrder order = new StockOrder();
        order.setSid(stock.getId());
        order.setName(stock.getName());
        orderMapper.insertSelective(order);
        logger.info("订单ID：{}", order.getId());

        return order.getId();
    }

}
